#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` in.vcf
exit 65
}

while getopts  ":b:p:" opts
do
	case  $opts  in
	b) build=$OPTARG;;
	p) out_prefix=$OPTARG;;
	*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi


. $var

if test -z "$build"; then build=hg19; fi

annovar_path=$tools_path/annovar
annovar_db_path=$annovar_path/$build


$annovar_path/table_annovar.pl $1 $annovar_db_path -vcfinput -buildver $build -out $out_prefix -remove -protocol 1000g2014oct_all,exac03,cadd -operation f,f,f -nastring .



# hg19_multianno

cat $out_prefix.hg19_multianno.vcf|sed 's/1000g2014oct_all/g1k2014oct_all/g' > $out_prefix.annovar.vcf

:<<date0728
rename $out_prefix.${build}_multianno.vcf $out_prefix.annovar.vcf $out_prefix.${build}_multianno.vcf
. $cmd_done

$annovar_path/table_annovar.pl $1 $annovar_db_path -vcfinput -buildver $build -out $out_prefix -remove -protocol refGene,cytoBand,genomicSuperDups,clinvar_20150629,cosmic70,ljb23_pp2hvar,ljb23_pp2hdiv,ljb23_sift,ljb23_mt -operation g,r,r,f,f,f,f,f,f -nastring . --thread 6

date0728
# WARNING to old ANNOVAR users: this program no longer does line-to-line conversion for multi-sample VCF files. If you want to include all variants in output, use '-format vcf4old' or use '-format vcf4 -allsample -withfreq' instead.

# no need to filter because will do it using gatk
# $annovar_path/convert2annovar.pl --format vcf4 --includeinfo --coverage 20 --fraction 0.05 --outfile $out_prefix.avi.impact.txt $1

:<<date0531
$annovar_path/convert2annovar.pl --format vcf4 --includeinfo --outfile $out_prefix.avi.impact.txt $1

$annovar_path/table_annovar.pl $out_prefix.avi.impact.txt $annovar_db_path -buildver $build -out $out_prefix.impact -remove -protocol knowngene,refGene,cosmic70,ljb26_all,esp6500si_all,snp138,1000g2014oct_all  -operation g,g,f,f,f,f,f --thread 6
date0531


# Error in argument: -csvout is not compatible with -vcfinput
# Error in argument: -nastring must be '.' when '-vcfinput' is specified


. $cmd_done